//
//  ViewController.m
//  03_UIResponder
//
//  Created by li cheng on 16/7/18.
//  Copyright © 2016年 li cheng. All rights reserved.
//

#import "ViewController.h"
#import "TouchView.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    TouchView *touchView = [[TouchView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
    touchView.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:touchView];
    
    // 1.响应者链
    // 检测顺序: 硬件 -> Appdelegate -> UIApplication ->UIWindow -> UIViewController -> self.view -> TouchView
    // 响应顺序:TouchView -> self.view -> UIViewController -> UIWindow -> UIApplication -> Appdelegate -> null
    // 如果所有的响应者都无法响应事件,则这个事件会被舍弃
    // 俩种监测响应者的方法
    // 1. Category 实现 touchBegin 的方法
    // 2. nectResponder
    
    
    // 例:
    // 1.响应者不要出边界,出边界响应者无法响应
    // 判断当前的点,在谁的范围内
    BOOL isInside = [touchView pointInside:CGPointMake(10, 10) withEvent:nil];
    NSLog(@"%@", isInside ?@"yes":@"no");
    
    UIButton *buttton = [UIButton buttonWithType:UIButtonTypeSystem];
    buttton.frame = CGRectMake(-100, -100, 100, 50);
    buttton.backgroundColor = [UIColor greenColor];
    [touchView addSubview:buttton];
    [buttton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
    // 2. button的点击方法如何实现
    // button点击效果,通过UIResponder对应的方法实现的
    // 3. pointInside重写,实现失去响应能力(return NO)
}


- (void)buttonClicked:(UIButton *)button{
    NSLog(@"%@", button);
}



- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [super touchesBegan:touches withEvent:event];
    NSLog(@"%@----------------%s", [self class], __FUNCTION__);
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
